//
//  Created by Jesse Squires
//  http://www.jessesquires.com
//
//
//  Documentation
//  http://cocoadocs.org/docsets/JSQMessagesViewController
//
//
//  GitHub
//  https://github.com/jessesquires/JSQMessagesViewController
//
//
//  License
//  Copyright (c) 2014 Jesse Squires
//  Released under an MIT license: http://opensource.org/licenses/MIT
//

#import "UIImage+JSQMessages.h"

#import "NSBundle+JSQMessages.h"


@implementation UIImage (JSQMessages)

- (UIImage *)jsq_imageMaskedWithColor:(UIColor *)maskColor {
    NSParameterAssert(maskColor != nil);

    CGRect imageRect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
    UIImage *newImage = nil;

    UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, self.scale);
    {
        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextScaleCTM(context, 1.0f, -1.0f);
        CGContextTranslateCTM(context, 0.0f, -(imageRect.size.height));

        CGContextClipToMask(context, imageRect, self.CGImage);
        CGContextSetFillColorWithColor(context, maskColor.CGColor);
        CGContextFillRect(context, imageRect);

        newImage = UIGraphicsGetImageFromCurrentImageContext();
    }
    UIGraphicsEndImageContext();

    return newImage;
}

+ (UIImage *)jsq_bubbleImageFromBundleWithName:(NSString *)name {
    NSBundle *bundle = [NSBundle jsq_messagesAssetBundle];
    NSString *path = [bundle pathForResource:name ofType:@"png" inDirectory:@"Images"];
    return [UIImage imageWithContentsOfFile:path];
}

+ (UIImage *)jsq_bubbleRegularImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"bubble_regular"];
}

+ (UIImage *)jsq_bubbleRegularTaillessImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"bubble_tailless"];
}

+ (UIImage *)jsq_bubbleRegularStrokedImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"bubble_stroked"];
}

+ (UIImage *)jsq_bubbleRegularStrokedTaillessImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"bubble_stroked_tailless"];
}

+ (UIImage *)jsq_bubbleCompactImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"bubble_min"];
}

+ (UIImage *)jsq_bubbleCompactTaillessImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"bubble_min_tailless"];
}

+ (UIImage *)jsq_defaultAccessoryImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"clip"];
}

+ (UIImage *)jsq_defaultTypingIndicatorImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"typing"];
}

+ (UIImage *)jsq_defaultPlayImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"play"];
}

+ (UIImage *)jsq_bubbleVoiceImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chat_bottom_voice_nor"];
}

+ (UIImage *)jsq_bubbleFaceImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chat_bottom_smile_nor"];
}

+ (UIImage *)jsq_bubbleOtherImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chat_bottom_up_nor"];
}

+ (UIImage *)jsq_bubbleKeyImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chat_bottom_keyboard_nor"];
}

+ (UIImage *)jsq_defaultLeftAudioImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"jsq_audio_left_3"];
}

+ (UIImage *)jsq_defaultLeft1AudioImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"jsq_audio_left_1"];
}

+ (UIImage *)jsq_defaultLeft2AudioImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"jsq_audio_left_2"];
}

+ (UIImage *)jsq_defaultRightAudioImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"jsq_audio_right_3"];
}

+ (UIImage *)jsq_defaultRight1AudioImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"jsq_audio_right_1"];
}

+ (UIImage *)jsq_defaultRight2AudioImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"jsq_audio_right_2"];
}

+ (UIImage *)jsq_bubbleToolsFromBundleWithName:(NSString *)name {
    NSBundle *bundle = [NSBundle jsq_messagesAssetBundle];
    NSString *path = [bundle pathForResource:name ofType:@"png" inDirectory:@"Tools"];
    return [UIImage imageWithContentsOfFile:path];
}

+ (UIImage *)jsq_categoryPhoto {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_photo_normal"];
}

+ (UIImage *)jsq_categoryPicture {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_picture_normal"];
}

+ (UIImage *)jsq_categoryLocation {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_location_normal"];
}

+ (UIImage *)jsq_categoryRecommend {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_goods_normal"];
}

+ (UIImage *)jsq_categorySymptom {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_body_normal"];
}

+ (UIImage *)jsq_categoryHealthcare {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_plan_normal"];
}

+ (UIImage *)jsq_categoryHealthy {
    return [UIImage jsq_bubbleToolsFromBundleWithName:@"image_button_healthy_normal"];
}

+ (UIImage *)jsq_expression:(NSString *)expression {
    NSBundle *bundle = [NSBundle jsq_messagesAssetBundle];
    NSString *path = [bundle pathForResource:expression ofType:@"png" inDirectory:@"Face"];
    return [UIImage imageWithContentsOfFile:path];
}

+ (UIImage *)jsq_VoiceHighlight {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chat_bottom_voice_highlight"];
}

+ (UIImage *)jsq_VoiceNor {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chat_bottom_voice_nor"];
}

+ (UIImage *)jsq_bubbleIndicateImage:(NSString *)name {
    return [UIImage jsq_bubbleImageFromBundleWithName:name];
}

+ (UIImage *)jsq_bubbleCancelImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"chexiao"];
}

+ (UIImage *)jsq_bubbleRecordImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"yuyin"];
}

+ (UIImage *)jsq_bubbleWarningImage {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"warning"];
}

+ (UIImage *)jsq_imageOperation {
    return [UIImage jsq_bubbleImageFromBundleWithName:@"btn_photo_image_save"];
}

@end
